home *** CD-ROM | disk | FTP | other *** search
- /**
- * mainFrame.java
- *
- * Title: ASCII Shop
- * Description: The goal of this program is to provide many functionalities of photoshop, with ASCII art.
- * @author Expotech
- * @version
- */
-
- package asciiShop;
-
- import java.awt.*;
- import java.awt.event.*;
- import java.io.*;
-
- public class mainFrame extends java.awt.Frame {
-
- char[][] artBuffer2;
- int useLength, length1, length2;
- int globalCount = 0;
- PrintWriter writeToFile;
- String bigString;
- int i, j, k;
- int countForOpenFile, countForOpenFileSave;
- FileDialog newFile;
- String pathToFile;
- String file;
- BufferedReader openFile;
- String[] artBuffer;
- String[][] layerBuffer;
-
- // IMPORTANT: Source code between BEGIN/END comment pair will be regenerated
- // every time the form is saved. All manual changes will be overwritten.
- // BEGIN GENERATED CODE
- // member declarations
- java.awt.TextArea fileBuffer = new java.awt.TextArea();
- java.awt.List layers = new java.awt.List();
- java.awt.MenuBar menuBar1 = new java.awt.MenuBar();
- java.awt.Menu menuFile = new java.awt.Menu();
- java.awt.MenuItem menuFileOpen = new java.awt.MenuItem();
- java.awt.MenuItem menuFileWriteOut = new java.awt.MenuItem();
- java.awt.MenuItem menuFileQuit = new java.awt.MenuItem();
- java.awt.Menu menuLayers = new java.awt.Menu();
- java.awt.MenuItem menuLayersAddLayer = new java.awt.MenuItem();
- java.awt.MenuItem menuLayersRemoveLayer = new java.awt.MenuItem();
- java.awt.MenuItem menuLayersRedrawLayers = new java.awt.MenuItem();
- // END GENERATED CODE
-
- public mainFrame() {
- }
-
- public void initComponents() throws Exception {
- // IMPORTANT: Source code between BEGIN/END comment pair will be regenerated
- // every time the form is saved. All manual changes will be overwritten.
- // BEGIN GENERATED CODE
- // the following code sets the frame's initial state
-
- fileBuffer.setLocation(new java.awt.Point(60, 70));
- fileBuffer.setVisible(true);
- fileBuffer.setSize(new java.awt.Dimension(480, 360));
-
- layers.setLocation(new java.awt.Point(570, 270));
- layers.setVisible(true);
- layers.setSize(new java.awt.Dimension(130, 160));
-
- menuBar1.add(menuFile);
- menuBar1.add(menuLayers);
-
- menuFile.setLabel("File");
- menuFile.add(menuFileOpen);
- menuFile.add(menuFileWriteOut);
- menuFile.add(menuFileQuit);
-
- menuFileOpen.setLabel("Open");
-
- menuFileWriteOut.setLabel("Write Out");
-
- menuFileQuit.setLabel("Quit");
-
- menuLayers.setLabel("Layers");
- menuLayers.add(menuLayersAddLayer);
- menuLayers.add(menuLayersRemoveLayer);
- menuLayers.add(menuLayersRedrawLayers);
-
- menuLayersAddLayer.setLabel("Add Layer");
-
- menuLayersRemoveLayer.setLabel("Remove Layer");
-
- menuLayersRedrawLayers.setLabel("Redraw Layers");
-
- setLocation(new java.awt.Point(5, 40));
- setTitle("asciiShop.mainFrame");
- setLayout(null);
- setMenuBar(menuBar1);
- setSize(new java.awt.Dimension(736, 520));
- add(fileBuffer);
- add(layers);
-
-
- fileBuffer.addTextListener(new java.awt.event.TextListener() {
- public void textValueChanged(java.awt.event.TextEvent e) {
- fileBufferTextValueChanged(e);
- }
- });
- layers.addItemListener(new java.awt.event.ItemListener() {
- public void itemStateChanged(java.awt.event.ItemEvent e) {
- layersItemStateChanged(e);
- }
- });
- menuFileOpen.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent e) {
- menuFileOpenActionPerformed(e);
- }
- });
- menuFileWriteOut.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent e) {
- menuFileWriteOutActionPerformed(e);
- }
- });
- menuLayersAddLayer.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent e) {
- menuLayersAddLayerActionPerformed(e);
- }
- });
- addWindowListener(new java.awt.event.WindowAdapter() {
- public void windowClosing(java.awt.event.WindowEvent e) {
- thisWindowClosing(e);
- }
- });
-
- // END GENERATED CODE
- }
-
- private boolean mShown = false;
-
- public void addNotify() {
- super.addNotify();
-
- if (mShown)
- return;
-
- // move components to account for insets
- Insets insets = getInsets();
- Component[] components = getComponents();
- for (int i = 0; i < components.length; i++) {
- Point location = components[i].getLocation();
- location.move(location.x, location.y + insets.top);
- components[i].setLocation(location);
- }
-
- mShown = true;
- }
-
- // Close the window when the close box is clicked
- void thisWindowClosing(java.awt.event.WindowEvent e) {
- setVisible(false);
- dispose();
- System.exit(0);
- }
-
- public void list1ItemStateChanged(java.awt.event.ItemEvent e) {
- }
-
- public void layersItemStateChanged(java.awt.event.ItemEvent e) {
- }
-
- public void fileBufferTextValueChanged(java.awt.event.TextEvent e) {
- }
-
- public void menuFileOpenActionPerformed(java.awt.event.ActionEvent e) {
- bigString = new String("");
- countForOpenFile = 0; // To get the number of lines to use with artBuffer
- newFile = new FileDialog(this, "Open File", FileDialog.LOAD); // Opens and open file dialog box
- newFile.setVisible(true);
- pathToFile = newFile.getDirectory();
- file = newFile.getFile();
- artBuffer = new String[200];
- try {
- System.out.println(pathToFile + file);
- openFile = new BufferedReader(new FileReader(pathToFile + file));
- } catch(FileNotFoundException badStuff) {
- System.out.println("The file could not be found... DAMN MICROSOFT!!!");
- }
- try {
- while( (artBuffer[countForOpenFile] = openFile.readLine()).equals("***end***") == false)
- {
- countForOpenFile++;
- }
- } catch(IOException badStuff) {
- System.out.println("HOW THE HELL DiD YOU GET THIS ERROR!?");
- }
- System.out.println("How many lines in the art: " + countForOpenFile);
- for(i = 0; i < countForOpenFile; i++) {
- bigString = bigString + artBuffer[i] + "\n";
- }
- fileBuffer.setText(bigString);
- countForOpenFileSave = countForOpenFile;
- }
-
- public void menuFileWriteOutActionPerformed(java.awt.event.ActionEvent e) {
- newFile = new FileDialog(this, "Save File", FileDialog.SAVE);
- newFile.setVisible(true);
- pathToFile = newFile.getDirectory();
- file = newFile.getFile();
- try {
- writeToFile = new PrintWriter(new FileWriter(pathToFile + file), true);
- System.out.println("Wrote to file: " + pathToFile + file);
- } catch(IOException badStuff) {
- System.out.println("GODDAMN HOW THE HELL DID YOU MANAGE TO GET THIS ERROR!?");
- }
- bigString = fileBuffer.getText();
- writeToFile.println(bigString + "\n***end***");
- System.out.println("Wrote out to file: " + pathToFile + file + "\n" + bigString + "***end***");
- return;
- }
-
- public void menuLayersAddLayerActionPerformed(java.awt.event.ActionEvent e) {
- layerBuffer = new String[globalCount][];
- globalCount++;
- bigString = new String("");
- countForOpenFile = 0; // To get the number of lines to use with artBuffer
- newFile = new FileDialog(this, "Add Layer", FileDialog.LOAD); // Opens and open file dialog box
- newFile.setVisible(true);
- pathToFile = newFile.getDirectory();
- file = newFile.getFile();
- layerBuffer[globalCount] = new String[200];
- System.out.println("Trying to apply layer: " + pathToFile + file);
- try {
- openFile = new BufferedReader(new FileReader(pathToFile + file));
- } catch(IOException badStuff) {
- System.out.println("HOW THE HELL DID YOU GET THIS ERROR!? - 3");
- }
- try {
- while( (layerBuffer[globalCount][countForOpenFile] = openFile.readLine()).equals("***end***") == false)
- {
- countForOpenFile++;
- }
- } catch(IOException badStuff) {
- System.out.println("HOW THE HELL DID YOU GET THIS ERROR!? -2");
- }
- length1 = artBuffer[0].length();
- length2 = layerBuffer[globalCount][0].length();
- if(length1 < length2) {
- useLength = length2;
- }
- else {
- useLength = length1;
- }
-
- artBuffer2 = new char[countForOpenFile][useLength];
-
- for(i = 0; i < countForOpenFileSave; i++) {
- for(k = 0; k < useLength; k++) {
- artBuffer2[i][k] = artBuffer[i].charAt(k);
- }
- for(j = 0; j < useLengthl j++) {
- if(artBuffer[i].charAt(j) != ' ') {
- artBuffer2[i][j] = artBuffer[i].charAt(j);
- }
- else {
- artBuffer2[i][j] = ' ';
- }
- }
- }
- for(i = 0; i < countForOpenfileSave; i++) {
- for(k = 0; k < useLength; k++) {
- System.out.println(artBuffer2[i][k];
- }
- }
- }
-
- /*layerBuffer = new String[globalCount][];
- layerBuffer[2] = new String[2]{"blah","soo"};
- system.out.println(layerBuffer[2][1])*/
- }
-